#include <stdio.h>
#include <stdlib.h>

int median(int A[], int B[], int L)
{
    int i = 1;
    int j = 1;
    int n = 0;
    while (n < L)
    {
        n = n + 1;
        if (n < L && (A[i - 1] < B[j - 1] || A[i - 1] == B[j - 1]))
        {
            i = i + 1;
        }
        if (n < L && A[i - 1] > B[j - 1])
        {
            j = j + 1;
        }
    }
    return A[i - 1] > B[j - 1] ? B[j - 1] : A[i - 1];
}

int main()
{
    int A[5] = {11, 13, 15, 17, 19};
    int B[5] = {2, 4, 6, 8, 20};
    int L = 5;
    printf("%d\n", median(A, B, L));
    system("pause");
}